<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Currency
 *
 * @author Sebastian
 */
class Common_View_Formatter_Currency
{
    const es_AR = "es_AR";
    const es_ES = "es_ES";
    const en_EN = "en_EN";

    public static function format($amount, $decimals= 2, $decimal_point=",",$left_digits=0, $thousands_sep=".", $thousands = false)
    {
        $zeroes = "0000000000000000000000";
        if( $thousands )
            $return = number_format($amount,$decimals,$decimal_point,$thousands_sep);
        else
            $return = number_format($amount,$decimals,$decimal_point,'');

        if( $left_digits > 0)
        {
            $return = $zeroes.$return;
            $start = ($left_digits + 3) * (-1);
            $return = substr($return,$start);
        }
        return $return;
    }

    public static function getValueOfRepresentation($value, $format )
    {
        if($format == self::es_AR || $format == self::es_ES)
        {
            $val = explode(",",$value);
            $val[0] = str_replace(".", "", $val[0]);

            $value = $val[0].".".$val[1];
            return $value;
        }
        elseif( $format == self::en_EN )
        {
            $val = explode(".",$value);
            $val[0] = str_replace(",", "", $val[0]);

            $value = $val[0].".".$val[1];
            return $value;
        }
        
        return $value;
    }
}
?>
